<?php

namespace Lib;

class Auth {
	
	protected $user;
	
	public static function check()
	{
		return \Session::get('USER_ID') !== NULL;
	}
	
	public static function get($user_id = 0)
	{
		$user_id = (int) $user_id;
		if( !$user_id )
		{
			return $this->user;
		}
		else
		{
			return \Model_User::query()->where('id', '=', $user_id)->get_one();
		}
	}
	
	public static function login($username = null, $password = null)
	{
		if(!empty($username) && !empty($password))
		{
			if( !($this->user == $this->validate_user($username, $password)) )
			{
				
			}
			return false;
		}
		
		return false;
	}
	
	public function validate_user($username_or_email, $password)
	{
		$user = \Model_User::query()
					->where_open()
						->where('username', '=', $username_or_email)
						->or_where('email', '=', $username_or_email)
					->where_close()
					->where('password', '=', $this->hash_password($password))
					->get_one();
		return $user ?: false;
	}
	
	public function hash_password($password)
	{
		
	}

}